package cate.game.play.buff.h;

import cate.game.play.buff.BuffHandler;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import easy.java.struct.ref.DoubleRef;

import java.util.ArrayList;
import java.util.List;

/**
 * 均摊我方所有单位受到的技能伤害
 */
public class 分摊伤害BH extends BuffHandler {

	@Override
	public void shareDamage(ActionCtx action, Fighter actor, int reason, DoubleRef doubleRef) {
		List<Fighter> targets = new ArrayList<>();
		for (Fighter fighter : buff.owner.getFightTeam().getFightersAlive()) {
			if (fighter.buff.containTid(buff.tid)) {
				targets.add(fighter);
			}
		}
		if (targets.isEmpty()) {
			return;
		}
		double shareDamage = doubleRef.v / targets.size();
		for (Fighter target : targets) {
			if (target.getPid() != buff.owner.getPid()) {
				target.attr.shareHurt(action, actor,buff, shareDamage);
			}
		}
		doubleRef.v = shareDamage;
	}
}
